<?php

namespace app\api\controller;

use app\common\controller\Api;

use app\admin\model\biz\BizInfo;
/**
 * 商户地点接口
 */
class Biz extends Api
{
    protected $noNeedLogin = [];
    protected $noNeedRight = '*';


    public function create(){
        $params=$this->request->post();
        $params['uid']=$this->uid();
        $params['is_biz']=1;
        $result=BizInfo::create($params);
        $this->success($result);
    }

    public function update(){
        $params=$this->request->post();
        unset($params['status'],$params['is_biz']);
        $result=BizInfo::update($params,['id'=>$params['id']]);
        $this->success('',$result);
    }

    public function list(){
        $params=$this->request->post();
        $list=(new BizInfo())->getList($params);
        $this->success('',$list);
    }

    public function info(){
        $id=$this->request->get('id');
        if(empty($id)){
            $info=(new BizInfo())->where(['uid'=>$this->uid()])->order('id','desc')->find();
        }else{
            $info=(new BizInfo())->where(['id'=>$id])->order('id','desc')->find();
        }
        $info['config'] = explode(',',$info['config'] ?? '');
        $info['images'] = explode(',',$info['images'] ?? '');
        $info['auth_images'] = explode(',',$info['auth_images'] ?? '');
        $this->success('',$info);
    }

}
